package main

import (
	"crypto/sha256"
	"fmt"
	"strings"
	"unicode/utf8"
)

func main() {
	sum := 0
	for i := 0; i < 10; i++ {
		sum += i
	}
	fmt.Printf("sum： %d", sum)

	oldMap := make(map[string]int)
	oldMap["gaga"] = 100
	oldMap["haha"] = 101
	newMap := make(map[string]int)
	for key, value := range oldMap {
		newMap[key] = value
	}
	fmt.Println(newMap)

	for key := range oldMap {
		fmt.Println(key)
	}

	x := 0
	for x < 10 {
		fmt.Printf("x 值:%d\r\n", x)
		x++
	}

	fmt.Println("------------------")
	for pos, char := range "中国语言" { // \x80 is an illegal UTF-8 encoding
		fmt.Printf("character %#U starts at byte position %d\n", char, pos)
	}

	//fmt.Printf("%d", unhex(100))
	fmt.Println("------------------")
	word := "世界"
	fmt.Printf("世界 len:%d\n", len(word))
	fmt.Printf("世界 RuneCountInString:%d\n", utf8.RuneCountInString(word))

	fmt.Println("------------------")
	char1 := '汉'
	fmt.Printf("汉 码点: %#U\n", char1)

	fmt.Println("------------------")
	fmt.Println("执行完毕")

	word1 := "我的世界开始下雪，冷的无法多爱一天"
	word2 := "开始下雪"
	fmt.Println(strings.Contains(word1, word2))

	arrExercise()
}

func arrExercise() {
	const (
		USD int = iota
		EUR
		GBP
		RMB
	)
	symbol1 := [...]string{USD: "$", EUR: "", RMB: "￥"}
	fmt.Println(RMB, symbol1[RMB])

	r := [...]int{99: -5, -6}
	fmt.Println(len(r))

	c1 := sha256.Sum256([]byte("x"))
	fmt.Println(c1)
	zero1(&c1)
	fmt.Println(c1)

	c2 := sha256.Sum256([]byte("X"))
	fmt.Println(c2)
	zero2(c2)
	fmt.Println(c2)
}

func zero1(ptr *[32]byte) {
	for i := range ptr {
		ptr[i] = 0
	}
}

func zero2(arr [32]byte) {
	for i := range arr {
		arr[i] = 0
	}
}
